$(function(){
    $('#btnQuery').click(function(){
        let keyword=$('[name=keyword]').val();
        let obj={
            keyword,
        }
        $.post('/product/query',obj,function(res){
            $('.tbRow').html('');
            res.forEach(item => {
                let html=`
                <tr class="tbRow">
                <td>${item.Id}</td>
                <td>${item.ProductName}</td>
                <td>${item.Supplier}</td>
                <td>${item.Price}</td>
                <td>${item.Stock}</td>
                <td>${item.Remarks}</td>
                <td>
                    <input type="button" value="编辑" onclick="btnEdit(${item.Id})" class="btnEdit">
                    <input type="button" value="shanc" onclick="btnDel(${item.Id})" class="btnDel">
                </td>
            </tr>
                
                `
                $('#tb').append(html);
            });
        })
    })
    $('#btnAdd').click(function(){
  window.location.href=`/product/createOrEdit`
    })
    $('#btnSave').click(function(){
        let ProductName=$('[name=productName]').val();
        let Supplier=$('[name=supplier]').val();
        let Price=$('[name=price]').val();
        let Stock=$('[name=stork]').val();
        let Remarks=$('[name=remarks]').val();
        let obj={
            ProductName,
            Supplier,
            Price,
            Stock,
            Remarks,
        }
        $.post('product/save',obj,function(){
            alert('保存成功')
            window.location.href=`/product/index`
        })
    })
    $('#btnCancel').click(function(){
        window.location.href=`/product/index`
    })

})
function btnEdit(id){
    window.location.href=`/product/createOrEdit${id}`
}
function btnDel(id){
    let m='真的要删除吗？'
    if(confirm(m)){
        window.location.href=`/product/delete${id}`
    }
}